package servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import util.Authorizer;
import exception.NotLoginedException;

/**
 * Servlet implementation class NewServlet
 */
@WebServlet("/NewServlet")
public class NewServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public NewServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

		//ログインを確認
		try{
			Authorizer a = new Authorizer(request);
			a.isLogined();
		}
		//ログインしていない場合、ログイン画面に遷移させる
		catch (NotLoginedException nle){
			this.getServletContext().getRequestDispatcher("/login.jsp").forward(request, response);
			return;
		}
		//認証済みの場合、メニュー画面に遷移
		this.getServletContext().getRequestDispatcher("/new.jsp").forward(request, response);
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//GETリクエストが来た時の例外処理を追加
	}
}
